﻿@using Microsoft.Extensions.Options;
@using SimpleIdServer.IdServer.Options;
@using SimpleIdServer.IdServer.ConformanceSuite.Startup.Resources;
@model SimpleIdServer.IdServer.Sms.UI.ViewModels.AuthenticateSmsViewModel
@inject IOptions<IdServerHostOptions> configuration

@{
    ViewBag.Title = AuthenticateSmsResource.title;
}
            
@if (!ViewData.ModelState.IsValid)
{
    <ul class="list-group">
        @foreach (var modelState in ViewData.ModelState.Values)
        {
            foreach (var error in modelState.Errors)
            {
                <li class="list-group-item list-group-item-danger">@AuthenticateSmsResource.ResourceManager.GetString(error.ErrorMessage)</li>
            }
        }
    </ul>
}

<div class="alert alert-info">
    @string.Format(AuthenticateSmsResource.code_validity, Model.TOTPStep)
</div>

<!-- Login form -->
@using (Html.BeginForm("Index", "Authenticate", new { area = "sms", returnUrl = Model.ReturnUrl }, FormMethod.Post))
{
    @Html.AntiForgeryToken()
    <input type="hidden" asp-for="ReturnUrl" />
    <input type="hidden" name="Action" value="AUTHENTICATE" />
    <div class="input-group mb-3">
        <input asp-for="Login" type="text" class="form-control" placeholder="@AuthenticateSmsResource.phonenumber" />
    </div>
    <div class="input-group mb-3">
        <input asp-for="OTPCode" type="password" class="form-control" placeholder="@AuthenticateSmsResource.confirmationcode" />
    </div>
    <div>
        <input type="checkbox" asp-for="RememberLogin " />
        <label>@AuthenticateSmsResource.remember_login</label>
    </div>
    <button type="submit" class="btn btn-primary card-link">@AuthenticateSmsResource.authenticate</button>
}

<!-- Senc confirmation code -->
@if (!string.IsNullOrWhiteSpace(ViewBag.SuccessMessage))
{
    <div class="alert alert-success">@AuthenticateSmsResource.ResourceManager.GetString(ViewBag.SuccessMessage)</div>
}
@using (Html.BeginForm("Index", "Authenticate", new { area = "sms", returnUrl = Model.ReturnUrl }, FormMethod.Post))
{
    @Html.AntiForgeryToken()
    <input type="hidden" asp-for="ReturnUrl" />
    <input type="hidden" name="Action" value="SENDCONFIRMATIONCODE" />
    <div class="input-group mb-3">
        <input asp-for="Login" type="text" class="form-control" placeholder="@AuthenticateSmsResource.phonenumber" />
    </div>
    <button type="submit" class="btn btn-primary card-link">@AuthenticateSmsResource.sendconfirmationcode</button>
}

<div>
    <div class="card">
        <div class="card-header">@AuthenticateSmsResource.title</div>
        <div class="card-body">
            @if (!string.IsNullOrWhiteSpace(Model.LogoUri))
            {
                <img class="card-img-top rounded mx-auto d-block" src="@Model.LogoUri" style="max-width: 300px" />
            }

            <h5 class="card-title">@Model.ClientName</h5>
            <div class="row">
                <div class="col-md-6">
                </div>
                <div class="col-md-6">

                </div>
            </div>
        </div>
        <div class="card-footer">
            <div style="float: right">
                @if (!string.IsNullOrWhiteSpace(Model.TosUri))
                {
                    <a href="@Model.TosUri" target="_blank">@AuthenticateSmsResource.tos</a>
                }

                @if (!string.IsNullOrWhiteSpace(Model.PolicyUri))
                {
                    <a href="@Model.PolicyUri" target="_blank">@AuthenticateSmsResource.policy</a>
                }
            </div>
        </div>
    </div>
</div>

@section SubScripts {
        <script type="text/javascript">
            $(document).ready(function () {
                $(".login input[name='RememberLogin']").change(function (e) {
                    $(this).val($(this).is(':checked'));
                });
            });
        </script>
}